package com.superteam.zzl.Des;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.superteam.zzl.activity.R;

import java.util.List;

/**
 * Created by Administrator on 2017/1/9.
 */
public class MyAdapter extends BaseAdapter {
    private Context context;
    private List<Country.DataBean.CityListBean> list;

    public MyAdapter(Context context, List<Country.DataBean.CityListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ViewHolder vh;
        if (convertView==null){
            vh=new ViewHolder();
            convertView=View.inflate(context, R.layout.graid_item,null);
            vh.iv=(ImageView)convertView.findViewById(R.id.grid_iv);
            vh.tv1=(TextView)convertView.findViewById(R.id.grid_tv1);
            vh.tv2=(TextView)convertView.findViewById(R.id.grid_tv2);
            convertView.setTag(vh);
        }else {
            vh=(ViewHolder)convertView.getTag();
        }
        vh.tv1.setText(list.get(position).place_name);
        vh.tv2.setText(list.get(position).place_name_en);
      //  vh.iv.setTag(list.get(position).cover_image);
        if (list.get(position).cover_image.length()>5){
//            new BitMapAsyncTask(context, new BitMapAsyncTask.CallBack() {
//                @Override
//                public void sendBitMap(String url, Bitmap bitmap) {
//
//                    if (url.equals(vh.iv.getTag())){
//                        vh.iv.setImageBitmap(bitmap);
//                    }
//                }
//            }).execute(list.get(position).cover_image);
            Glide.with(context).load(list.get(position).cover_image).into(vh.iv);
        }

        return convertView;
    }
    class ViewHolder{
        ImageView iv;
        TextView tv1,tv2;
    }
}
